package cn.iocoder.yudao.module.agent.convert.withdrawaccount;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.agent.base.MemberRespVO;
import cn.iocoder.yudao.module.agent.controller.admin.user.vo.AgentUserRespVO;
import cn.iocoder.yudao.module.agent.convert.base.AgentConvert;
import cn.iocoder.yudao.module.agent.dal.dataobject.user.AgentUserDO;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.agent.controller.admin.withdrawaccount.vo.*;
import cn.iocoder.yudao.module.agent.dal.dataobject.withdrawaccount.AgentWithdrawAccountDO;

/**
 * 代理人佣金提现账户 Convert
 *
 * @author 曹建伟
 */
@Mapper
public interface AgentWithdrawAccountConvert {

    AgentWithdrawAccountConvert INSTANCE = Mappers.getMapper(AgentWithdrawAccountConvert.class);

    AgentWithdrawAccountDO convert(AgentWithdrawAccountCreateReqVO bean);

    AgentWithdrawAccountDO convert(AgentWithdrawAccountUpdateReqVO bean);

    AgentWithdrawAccountRespVO convert(AgentWithdrawAccountDO bean);

    List<AgentWithdrawAccountRespVO> convertList(List<AgentWithdrawAccountDO> list);

    PageResult<AgentWithdrawAccountRespVO> convertPage(PageResult<AgentWithdrawAccountDO> page);

    List<AgentWithdrawAccountExcelVO> convertList02(List<AgentWithdrawAccountDO> list);

    default AgentWithdrawAccountRespVO convert(AgentWithdrawAccountDO bean, MemberRespVO memberRespVO){
        if ( bean == null ) {
            return null;
        }

        AgentWithdrawAccountRespVO agentWithdrawAccountRespVO = new AgentWithdrawAccountRespVO();

        agentWithdrawAccountRespVO.setUserId( bean.getUserId() );
        agentWithdrawAccountRespVO.setName( bean.getName() );
        agentWithdrawAccountRespVO.setAccountNo( bean.getAccountNo() );
        agentWithdrawAccountRespVO.setBankName( bean.getBankName() );
        agentWithdrawAccountRespVO.setBankAddress( bean.getBankAddress() );
        agentWithdrawAccountRespVO.setId( bean.getId() );
        agentWithdrawAccountRespVO.setCreateTime( bean.getCreateTime() );

        agentWithdrawAccountRespVO.setMember(memberRespVO);

        return agentWithdrawAccountRespVO;
    }

    default List<AgentWithdrawAccountRespVO> convertList02(List<AgentWithdrawAccountDO> accountDOList, Map<Long, MemberUserRespDTO> memberMap) {
        List<AgentWithdrawAccountRespVO> list = new ArrayList<>();
        accountDOList.forEach(accountDO -> {
            MemberRespVO memberRespVO = AgentConvert.INSTANCE.covnertMember(memberMap.get(accountDO.getUserId()));
            list.add(convert(accountDO, memberRespVO));
        });

        return list;
    }

    default  PageResult<AgentWithdrawAccountRespVO> convertPage2(PageResult<AgentWithdrawAccountDO> page, Map<Long, MemberUserRespDTO> memberMap){
        if ( page == null ) {
            return null;
        }

        PageResult<AgentWithdrawAccountRespVO> pageResult = new PageResult<AgentWithdrawAccountRespVO>();
        List<AgentWithdrawAccountRespVO> list = convertList02(page.getList(), memberMap);

        pageResult.setList(list);
        pageResult.setTotal(page.getTotal());

        return pageResult;
    }

}
